define(function(require, exports){
	var $ = require("jquery");
	var util = require('util');
	var pubjs = require('pubjs');
	var view  = require('@base/view');

	var Main = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-runninglogDetail'
			});

			this.Super('init', arguments);
		},
		afterBuild:function(){
			var el = this.getDOM();

			var doms = this.$doms = {
				con: $('<div class="P-runninglogDetailCon" />'),
				title: $('<div class="logTitle" />'),
				name: $('<div class="logName" />'),
				author: $('<div class="logAuthor" />'),
				time: $('<div class="logTime" />'),
				content: $('<div class="logContent" />')
			};

			doms.back = $('<div class="backBtn" data-op="back"><div></div>'+LANG('返回')+'</div>');
			doms.edit = $('<div class="backBtn editBtn" data-op="edit"><div></div>'+LANG('修改')+'</div>').hide();
			el.append(doms.back, doms.edit, doms.con);
			doms.con.append(doms.title, doms.name, doms.author, doms.time, doms.content);

			this.uiBind(doms.back, 'click', 'eventBack');
			this.uiBind(doms.edit, 'click', 'eventEdit');

			this.reset();
		},
		load: function() {
			var c = this.config;
			pubjs.loding.show();
			pubjs.mc.send(c.url, this.$param, this.onData.bind(this));
		},
		onData: function(err, data) {
			//隐藏加载状态提示
			pubjs.loding.hide();
			//从服务器返回数据失败
			if (err){
				pubjs.error(err);
				return false;
			}
			//成功返回数据
			if (data){
				this.setData(data);
			}
		},
		setParam:function(id){
			this.$param._id = id;
			return this;
		},
		setData: function(data) {
			this.$data = data;
			var doms = this.$doms;
			// 自己写的，有编辑按钮；别人写的就没有
			if (data.Edit){
				doms.edit.show();
			}
			doms.title.text(data.Title);
			doms.name.text(data.NickName);
			doms.author.text(data.Author);
			doms.time.text(util.date("Y-m-d",data.EditTime));
			doms.content.html(data.Content);
		},
		reset: function() {
			var doms = this.$doms;
			this.$data = {};
			this.$param = {};

			doms.title.text('');
			doms.name.text('');
			doms.author.text('');
			doms.time.text('');
			doms.content.html('');
			return this;
		},
		eventBack: function(ev){
			pubjs.controller.navigate('runninglog');
			return false;
		},
		eventEdit: function(ev){
			var id = this.$data && +this.$data._id || 0;
			pubjs.navigate('runninglog/edit/'+id);
			return false;
		}
	});
	exports.main = Main;
});